import axios from 'axios'
import { setAuthHeader, getTokenFromLocalStorage } from "./auth"


export default ({ req, isDev, route, redirect }) => {
    setAuthHeader(req)
    axios.interceptors.response.use(
      response => response,
      error => {
        if (
          error.response.status === 401 &&
          !getTokenFromLocalStorage() &&
          location.pathname !== '/login'
        ) {
          redirect('/login', { page: location.pathname + location.search })
        }
        return Promise.reject(error)
      }
    )
  axios.defaults.timeout = 20000
}
